//
//  VersionViewModel.swift
//  FeastBooking
//
//  Created by Imon on 2017/12/24.
//  Copyright © 2017年 Imon. All rights reserved.
//

import Foundation
import RxSwift
import Moya

class VersionViewModel {
    
    public static let share = VersionViewModel()
    
    private var provider: RxMoyaProvider<VersionApi>
    
    init() {
        let endpointClosure = { (target: VersionApi) -> Endpoint<VersionApi> in
            let defaultEndpoint = RxMoyaProvider.defaultEndpointMapping(for: target)
            return defaultEndpoint.adding(newHTTPHeaderFields: ["content-type": "application/json"])
        }
        provider = RxMoyaProvider<VersionApi>(endpointClosure: endpointClosure)
    }
    
    func getVersion() -> Observable<String> {
        return provider.request(.getVersion())
            .mapString()
    }

}
